<?php
namespace app\index\controller;
use think\Config;
use think\Db;

class Tipset extends Common
{
	//区块列表
    public function index()
    {
		$page=request()->param('page');
		if(!$page | $page<1)
		{
			$page = 1;
		}
		
		$url=Config::get("block_url");
		$url = $url . "v1/index/block/list";
		$arr['page']=$page;
		
		$info = $this->curl_request($url,$arr);
		$cinfo = json_decode($info,true);
		$data = $cinfo['data']['data'];
		foreach($data AS &$v)
		{
			foreach($v AS &$c)
			{
				$c['timestamp']=date("Y-m-d H:i:s",$c['timestamp']);
			}
			unset($c);
		}
		unset($v);
		
		
		$page_arr=array();
		$page_arr['this']=$page;
		$page_arr['next']=$page+1;
		$page_arr['pre']=$page-1;
		$page_arr['next_last']=$cinfo['data']['page'];
		
		
		
		$this->assign("data",$data);
		$this->assign("page",$page_arr);
		
		return $this->fetch();
    }
	
	
	//高度详情
	public function detail()
	{
		//$this->redirect("Index/index");
		$baseurl=Config::get("block_url");
		
		$id=request()->param('id');
		if(!$id | $id<1)
		{
			$id = 1;
		}
		
		$url=$baseurl.="v1/index/height/get";
		
		$arr['height']=$id;
		$info = $this->curl_request($url,$arr);
		$cinfo = json_decode($info,true);
		$height_data = $cinfo['data'];
		
		/*
		foreach($height_data AS &$v)
		{
			$v['reward'] = $v['reward'] /1000000000000000000;
			//$this->chk_num($v['reward'],3);
		}
		unset($v);
		*/
		
		$info=array();
		$info['height'] = $id;
		$info['time'] = date("Y-m-d H:i:s",$cinfo['echo']);
		
		
		
		
		$this->assign("info",$info);
		$this->assign("data",$height_data);
		
		return $this->fetch();
		
	}
	
}
